#include <iostream>
#include <sstream>
#include <math.h>
#include <conio.h>
#include <string.h>
using namespace std;

class Team{
    float scoreChance;
    public:
    string name;
    int won, lost;


    Team(string name_, int won_, int lost_){
        name = name_;
        won = won_; lost = lost_;
    }

    Team(){
    }

    string toString(){
        stringstream out[3];
        string temp(name);

        out[0] << won;
        temp.append(" "); temp.append(out[0].str());
        out[1] << lost;
        temp.append(" - "); temp.append(out[1].str());
        out[2] << scoreChance;
        temp.append("   chance: "); temp.append(out[2].str());
        return temp;
    }

    void calc(){
        scoreChance = (float) won / 2340;
    }

    bool scored(){
        float rndNo = (float) (rand()%10000)/10000;
        //cout << "" << rndNo << endl;
        if(rndNo < scoreChance) return true;
        return false;
    }


};

void loadTeamData(Team team[]){
    FILE* infil;
    infil = fopen("LAGNAMN.DAT", "rt");

    char name[20], slask[20];
    int won, lost;
    for(int i=1; i<=14; i++){
        fscanf(infil, "%s", name);
        fscanf(infil, "%s", slask);
        fscanf(infil, "%d", &won);
        fscanf(infil, "%d", &lost);
        team[i].name = name;
        team[i].won = won; team[i].lost = lost;
        team[i].calc();
    }
    fclose(infil);
}

int main(void){
    Team *team;
    team = new Team[15];
    loadTeamData(team);

    srand(time(0));

    int sum =0;
    for(int i=0; i<=2340; i++)
        if(team[2].scored())
            sum++;

    cout << team[2].name << " scored a total of " << sum << endl;


//    for(int i=1; i<=14; i++)
//        cout << team[i].toString() << endl;

    for(int i=0; i<=14; i++)
    delete (team);

    return 0;
}

